import { render, h } from "vue"
import AAlert from '../components/AAlert.vue'
import zhCN from '../lang/packs/zhCN'

export default {
    alert: (message, opts = {}) => {
        return new Promise(resolve => {
            let vNode = h(AAlert, {
                title: opts.title || opts?.caller?.$t('AAlert.Tips') || zhCN.AAlert.Tips,
                message: message,
                confirmText: opts.confirmText || opts?.caller?.$t('AAlert.Confirm') || zhCN.AAlert.Confirm,
                cancelText: opts.cancelText || opts?.caller?.$t('AAlert.Cancel') || zhCN.AAlert.Cancel,
                onConfirm(result) {
                    resolve(result)
                    render(null, window.document.body)
                },
            })
            render(vNode, window.document.body)
        })
    }
}